package com.example.demo.task;

import com.example.demo.mapper.MeetingUsageMapper;
import com.example.demo.service.MeetingUsageService;
import com.example.demo.service.MeetingUsageServiceImpl;
import com.example.demo.service.WeLinkApiService;
import com.example.demo.entity.MeetingUsage;
import com.example.demo.service.WeLinkApiServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Component
public class MeetingUsageTask {

    @Resource
    private WeLinkApiServiceImpl weLinkApiService;

    @Resource
    private MeetingUsageServiceImpl meetingUsageService;

    @Resource
    MeetingUsageMapper meetingUsageMapper;

    @PostConstruct
    @Scheduled(fixedRateString = "${spring.task.scheduling.fixed-rate}")
    public void executeTask() {
        try {
            // 调用WeLink API获取会议使用数据
            List<MeetingUsage> meetingUsages = weLinkApiService.getMeetingUsage();
            // 将数据存储到数据库中
            meetingUsageService.saveMeetingUsage(meetingUsages);

            MeetingUsage meetingUsage = new MeetingUsage();
            meetingUsage.setStatisticTime("2023-07-01");
            meetingUsage.setMeetingCount(10);
            meetingUsage.setAttendance(50);
            meetingUsage.setMeetTime(3600);
            meetingUsage.setMeetPeopleNumber(20);
            meetingUsage.setConcurrencyMax(8);


            meetingUsageMapper.insert(meetingUsage);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
